<template>
	<view>
		<view class="bottomPart">
			<view class="left">实付款：{{total}}</view>
			<!-- <view class="mid">取消</view> -->
			<view class="right" @click="payForOrder">立即支付</view>
		</view>
		<view><uni-notice-bar show-icon text="请在10秒内完成支付,否则订单将被取消" /></view>
	</view>
</template>

<script>
	export default {
		onLoad(e) {
			this.total = e.total;
		},
		data() {
			return {
				seckillInfoDTO: {}
			};
		},
		methods: {
			payForOrder() {
				var data = uni.getStorageSync('seckillInfo');
				var res = JSON.parse(data)
				console.log(res);
				this.seckillInfoDTO.orderNum = res.orderNum;
				this.seckillInfoDTO.killGood = res.killGood;
				let jwt = uni.getStorageSync('authority');
				uni.request({
					url: "api/appuser/paymentForSeckill",
					header: {
						"authority": jwt
					},
					method: 'POST',
					data: this.seckillInfoDTO,
					success: (res) => {
						console.log(res);
						if (res.data.code == 3003) {
							uni.showToast({
								title: "请勿重复付款",
								icon: 'error'
							})
							return;
						} else if (res.data.code == 3004) {
							uni.showToast({
								title: "订单已超时",
								icon: 'error'
							})
							setTimeout(function() {
								uni.switchTab({
									url: "/pages/index/index",
								})
							}, 2000);
							return;
						} else if (res.data.code == 200) {
							uni.showToast({
								title: "支付成功",
								icon: 'success'
							})
							setTimeout(function() {
								uni.switchTab({
									url: "/pages/index/index",
								})
							}, 1500);
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: rgb(244, 244, 244);
	}

	.bottomPart {
		position: fixed;
		bottom: var(--window-bottom);
		width: 750rpx;
		height: 120rpx;
		background-color: #fff;

		.left {
			float: left;
			line-height: 120rpx;
			margin-left: 20rpx;
			color: #fda28e;
			font-size: 30rpx;
		}

		.mid {
			float: left;
			margin-left: 100rpx;
		}

		.right {
			float: right;
			line-height: 100rpx;
			width: 200rpx;
			height: 100rpx;
			background-color: #5396e7;
			border-radius: 20rpx;
			text-align: center;
			color: #fff;
			margin-right: 20rpx;
		}
	}
</style>